# Maintainer: Santiago Torres-Arias <santiago @ usualplace>
# Contributor: Kaizhao Zhang <zhangkaizhao@gmail.com>

pkgname=python-hatch
pkgver=1.7.0
pkgrel=2
pkgdesc="A modern project, package, and virtual env manager"
arch=('any')
url="https://github.com/ofek/hatch"
license=('MIT')
depends=(
  'python' 'python-appdirs' 'python-atomicwrites' 'python-click'
  'python-colorama' 'python-coverage' 'python-pexpect' 'python-pip'
  'python-pytest' 'python-semver' 'python-setuptools' 'python-sortedcontainers'
  'python-toml' 'twine' 'python-userpath' 'python-virtualenv' 'python-wheel'
  'python-build'
)


_name=${pkgname/python-/}
source=(
  "https://files.pythonhosted.org/packages/source/${_name:0:1}/${_name}/${_name}-${pkgver}.tar.gz"
  'hatch_complete.sh'
  'hatch_complete.zsh'
)
sha256sums=('7afc701fd5b33684a6650e1ecab8957e19685f824240ba7458dcacd66f90fb46'
            'b87254c621719188907a2062b0aa3c4eb078088872d1de7d53d6a6d61a679c44'
            'a43679d72ebb7b5c029192519597eff835586d0b6ed9d1e3dfc93270b8720e71')

build() {
  cd "${srcdir}/${_name}-${pkgver}"
  python -m build
}

package() {
  cd "${srcdir}/${_name}-${pkgver}"
  PIP_CONFIG_FILE=/dev/null pip install --isolated --root="${pkgdir}" --ignore-installed --no-deps dist/*.whl
  install -Dm644 LICENSE.txt -t "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

  cd "${srcdir}"

  # Tab completions.
  # via https://github.com/ofek/hatch/issues/57 and
  # https://click.palletsprojects.com/en/7.x/bashcomplete/

  # Tab completion for Bash.
  # Generated by `_HATCH_COMPLETE=source hatch > hatch_complete.sh`
  install -Dm644 hatch_complete.sh "${pkgdir}/usr/share/bash-completion/completions/${_name}"

  # Tab completion for Zsh.
  # Generated by `_HATCH_COMPLETE=source_zsh hatch > hatch_complete.zsh`
  install -Dm644 hatch_complete.zsh "${pkgdir}/usr/share/zsh/site-functions/_${_name}"
}
